package com.docted.seckill.common;

/**
 * Created by DoCted on 2017/5/24
 * Description:
 */
public class Const {
    public enum SeckillStatusEnum {
        SUCCESS(1, "秒杀成功"),
        END(10, "结束"),
        REPEAT_KILL(-1, "重复异常"),
        INNER_ERROR(-2, "系统异常"),
        DATA_ILLEGAL(-3, "参数异常");

        private int code;
        private String value;

        SeckillStatusEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public static SeckillStatusEnum codeOf(int code) {
            for (SeckillStatusEnum seckillStatusEnum : values()) {
                if (seckillStatusEnum.getCode() == code) {
                    return seckillStatusEnum;
                }
            }
            throw new RuntimeException("没有找到对应的枚举");
        }

    }
}
